const container = document.getElementById('container')

const basePath = `${window.location.origin}/api/inverter/buffer?filePath=`
const getItemTemplate = item => {
    const url = `./web/viewer.html?id=${encodeURIComponent(basePath + item.pdf)}`
    return `<li>
                <a href="${url}" target="_blank">
                    <div class="db-pic">
                        <img src="/api/inverter/buffer?filePath=${item.image}">
                    </div>
                    <h3 class="db-txt">${item.title}</h3>
                </a>
            </li>`
}

fetch(`/api/inverter/data/sheet/list`).then(response => {
    if (response.status === 200) {
        return response.json()
    } else {
        return {code: 999, message: '系统错误'}
    }
}).then(result => {
    if (result.code === 200) {
        let template = ''
        for (let i = 0; i < result.data.length; i++) {
            template += getItemTemplate(result.data[i])
        }
        container.innerHTML = template
    } else {
        window.location.href = `./error.html`
    }
})
